package indv.cfeng.fianceCampus.common.result;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Cfeng
 * @date 2022/10/15
 */

@Data
public class Resp {

    private Integer code;

    private String message;

    private Map<String, Object> data = new HashMap<>();

    //私有构造器
    private Resp(){

    }

    //成功ok
    public static Resp ok() {
        Resp resp = new Resp();
        resp.setCode(ResponseEnum.SUCCESS.getCode());
        resp.setMessage(ResponseEnum.SUCCESS.getMessage());
        return resp;
    }

    //失败
    public static Resp failed() {
        Resp resp = new Resp();
        resp.setCode(ResponseEnum.ERROR.getCode());
        resp.setMessage(ResponseEnum.ERROR.getMessage());
        return resp;
    }

    //设置特定的结果
    public static Resp setResult(ResponseEnum responseEnum) {
        Resp resp = new Resp();
        resp.setCode(responseEnum.getCode());
        resp.setMessage(responseEnum.getMessage());
        return resp;
    }

    public Resp message(String message) {
        this.setMessage(message);
        return this;
    }

    public Resp code(Integer code) {
        this.setCode(code);
        return this;
    }

    public Resp data(String key, Object value) {
        this.data.put(key,value);
        return this;
    }
}
